<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html style="overflow: hidden;">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>我的工作台</title>
    <%@ include file="/WEB-INF/jsp/common/inc.jsp" %>
    <style type="text/css">
        .fixed-table-body{height:auto;}
        .main_a{width:100%;height:100%}
    </style>
</head>
<body>
<div class="main_a">
    <div  class="func_header">
        <span>当前位置 ：我的工作台 >待办事项</span>
    </div>
    <div class="func_bar"><!--   功能内容-->
        <div class="search_container">
            <div class="advanced_search" style="width: 100%;margin: 3px 0 0;">
                <div class="advanced_search_div"></div>
                <input type="text" name="projectSource" id="projectSource" onkeypress="judge_enter()" placeholder="请输入项目名称" />
                <a class="magnifier" id="search" href="javascript:;"   onclick="refreshTable()"></a>
            </div>
        </div>
        <div class="btn_container">
            <c:if test="${userName != '安全保密员' }">
                <a style="margin-top: 7px;" class="blue_btn" id="read" onclick="read()" href="javascript:;">标记为完成</a>
            </c:if>
        </div>
    </div>
    <div style="overflow: auto; width:98%;margin:0px auto 0px;">
        <table class="table table-bordered table_inline" id="secretInvolvedLevelList"></table>
    </div>
</div>
</body>
<script type="text/javascript">
var userName="<%=session.getAttribute("userName")%>";
	var layerIndex;
    var threeLevelList;
    $(function(){
        loadTable();
    })

    var work = "${work}";
    var numberBuilder = "${numberBuilder}";
    function loadTable(){
        threeLevelList = $("#secretInvolvedLevelList").bootstrapTable({
            url : '${_baseUrl}/myWorkbench/needHandleEvent?rand='+Math.random(),
            pagination: true,
            pageList: [5, 10, 20, 50],
            singleSelect  : false,
            queryParams: queryParams,
            columns : [{
                checkbox: true
            },{
                field: 'messageId',
                title: 'ID',
                visible:false,
                width: 5
            },{
                field: 'messageContent',
                title: '待办事项内容',
                width:200,
                formatter: function(value, row, index){
                	if(value.indexOf("重置了用户") != -1){
                 	   return "<a href='javascript:void(0)' onclick='openPwdResetMessage(\""+row.messageId+"\")'>"+value+"</a>";
                	}else if(value.indexOf("安全保密员") != -1){
                       return "<a href='javascript:void(0)' onclick='openBeginPwdResetMessage(\""+row.messageId+"\")'>"+value+"</a>";
                   	}else{
                		if(row.messageStatus =='2'){//标记数据
                			 return value;
                		}else{//未标记数据
                	        return "<a href='javascript:void(0)' onclick='toMessageDetail(\""+row.messageUrl+"\",\""+row.messageId+"\",\""+row.parentModelName+"\",\""+row.projectId+"\",\""+row.tableFlag+"\",\""+row.messageContent+"\")'>"+value+"</a>";
                		}
                	}
                }
            },{
                field: 'projectSource',
                title: '项目名称',
                width: 100,
	             formatter: function(value, row, index){
	            	 if('-' == value || '' == value){
	            		 return "-";
	            	 }else{
	            		 return value;
	            	 }
	             }
            },{
                field: 'createTime',
                title: '发送时间',
                width: 100
            }],
	        onLoadSuccess : function(data) {
	        	var cellIndex=parseInt($(".table_inline th").length);
	            $(".table_inline tr td").each(function(){
	                if(this.cellIndex != cellIndex){
	                    $(this).attr("title",$(this).text());
	                }
	            });
	  		},
        })
    }
    function refreshTable(){
        threeLevelList.bootstrapTable('refresh');
    }

    function selectProjectMessage(){
        threeLevelList.bootstrapTable('refresh');
    }
    function queryParams(params){
		return {
            pageSize: params.limit,
            pageNo: params.pn,
            sort : params.sort,
            order : params.order,
            projectName : $("#projectSource").val() == "请输入" ? null : $("#projectSource").val(),
	   }
	}

    function openPwdResetMessage(messageId){
    	var index =layer.open({
			  type: 2,
			  title:'密码确认页面',
			  shade:0.2,			//遮罩层颜色
			  area: ['1300px', '400px'],
			  fixed: false, //不固定
			  maxmin: true,
			  content: "${_baseUrl}/myWorkbench/pwdResetMessage?rand="+Math.random()
			});
		layer.full(index);
   }

   function openBeginPwdResetMessage(messageId){
		   var index =layer.open({
				  type: 2,
				  title:'初始密码页面',
				  shade:0.2,			//遮罩层颜色
				  area: ['1300px', '400px'],
				  fixed: false, //不固定
				  maxmin: true,
				  content: '${_baseUrl}/userController/userPwdResetPage?rand='+Math.random()
				});
			layer.full(index);
   }
    
    function sigh(messageId){
		$.ajax({
			url : '${_baseUrl}/workbench/updateNeedHandleEvent?id='+messageId,
			type : 'post', //数据发送方式 
			dataType : 'json', //接受数据格式 
			async : false,
			success : function(json) {
			},
			error : function() {
				layer.msg("系统错误,请联系管理员");
			}
		});	
   }
    
    
    
    function read(){
    	var selected = threeLevelList.bootstrapTable('getSelections');
    	if(selected.length < 1){
    		layer.msg("请选择需要标记的信息");
    		return false;
    	}
    	var ids = [];
    	for(var i=0;i<selected.length;i++){
    		ids.push(selected[i].messageId);
    	}
		
		$.ajax({
			url : '${_baseUrl}/workbench/updateNeedHandleEvent1?id='+ids,
			type : 'post', //数据发送方式
			dataType : 'json', //接受数据格式
			async : false,
			success : function(json) {
				if(json.code == '0'){
					layer.msg(json.message);
					refreshTable();
				}
			},
			error : function() {
				layer.msg("系统错误,请联系管理员");
			}
		});
    }
    function onclickLastMenu(){
    	refreshTable();
    	layer.closeAll();

    }

    function refreshTree(num,id){
    }

  //关闭弹框
    function onclickLastMenu(){
    	refreshTable();
    	layer.closeAll();
    }

    function getTestStr(tableFlag,messageContent) {
        var testStr = [];
        if(tableFlag === 'KP'){
            testStr.push(".*请.*构建.*");
        }else if (tableFlag === 'KD'){
            testStr.push(".*请.*构建.*");
        }else if (tableFlag === 'KT'){
            testStr.push(".*文档审查发现文档错误.*");
            testStr.push(".*请.*构建.*");
        }
        testStr.push(".*安全保密员已确认.*");
        var flag = false;

        for (var i = 0; i < testStr.length; i++) {
            var reg = RegExp(testStr[i]);
            if(reg.test(messageContent)){
                flag = true;
            }
        }
        return flag
    }

	function toMessageDetail(url,messageId,parentModelName,projectId,tableFlag,messageContent){
        if(getTestStr(tableFlag,messageContent)){
            $.ajax({
                url : '${_baseUrl}/workbench/updateNeedHandleEvent?id='+messageId,
                type : 'post', //数据发送方式
                dataType : 'json', //接受数据格式
                async : false,
                success : function(json) {
                },
                error : function() {
                    layer.msg("系统错误,请联系管理员");
                }
            });
        }
        var baseUrl = "${_baseUrl}";
        if(parentModelName == "配置管理" && url.indexOf(baseUrl) == -1){
        	url = "${_baseUrl}"+url;
        }
		if(parentModelName == "测试管理"){
			if(url.indexOf("/testCase/isExistCase") != '-1'){
				if(numberBuilder != 'tianjin712suo'){
					$.ajax({
				        type: "post",
				        dataType: "json",
				        url: '${_baseUrl}/index/updateMessageStatus',
				        data: {messageId:messageId},
				        success: function (data) {
				        	if("1" == data.code){
				        		$.ajax({
									url : url,
									type : 'post', //数据发送方式 
									dataType : 'json', //接受数据格式 
									async : false,
									success : function(json) {
										if(json.code == '1'){
											var testCaseId = json.data;
											var testRoundId = json.message;
											layerIndex1 = parent.layer.open({
												 type: 2,
												 title: '待办事项',
												 area: ['1000px', '350px'],
												 fixed: false, //不固定
												 maxmin: true,
												 shim: true,
												 content:"${_baseUrl}/testCase/toTestCaseAudit?testCaseId="+testCaseId+"&work="+work+"&testRoundId="+testRoundId+"&rand="+Math.random()
											});
											parent.layer.full(layerIndex1);
											parent.layerIndex = layerIndex1;
											refreshTable();
										}else{
											var projectId = json.data;
											parent.parent.closeAndSkip(parentModelName,"${_baseUrl}/testProcess/showTestProcessDemandMenu?projectId="+projectId,messageId);
										}
									},
									error : function() {
										layer.msg("系统错误,请联系管理员");
									}
								});	
				        	
				        	}
				        },
				        error:function(json){
							layer.msg("系统错误,请联系管理员");
						}
				    });
				}else{
					$.ajax({
						url : url,
						type : 'post', //数据发送方式 
						dataType : 'json', //接受数据格式 
						async : false,
						success : function(json) {
							if(json.code == '1'){
								var testCaseId = json.data;
								var testRoundId = json.message;
								layerIndex1 = parent.layer.open({
									 type: 2,
									 title: '待办事项',
									 area: ['1000px', '350px'],
									 fixed: false, //不固定
									 maxmin: true,
									 shim: true,
									 content:"${_baseUrl}/testCase/toTestCaseAudit?testCaseId="+testCaseId+"&work="+work+"&testRoundId="+testRoundId+"&rand="+Math.random()
								});
								parent.layer.full(layerIndex1);
								parent.layerIndex = layerIndex1;
								refreshTable();
							}else{
								var projectId = json.data;
								parent.parent.closeAndSkip(parentModelName,"${_baseUrl}/testProcess/showTestProcessDemandMenu?projectId="+projectId,messageId);
							}
						},
						error : function() {
							layer.msg("系统错误,请联系管理员");
						}
					});	
				}
				
			}else if(url.indexOf("/editProduct/synergyWrite") != '-1'){
				if(numberBuilder != 'tianjin712suo'){
					if(!updateNeedHandleEvent(messageId)){
						 return;
					}
				}else{updateNeedHandleEvent(messageId);}
				
				layerIndex2 = parent.layer.open({
					 type: 2,
					 title: '待办事项',
					 area: ['1000px', '350px'],
					 fixed: false, //不固定
					 maxmin: true,
					 shim: true,
					 content:url+"&random="+Math.random()
				});
				parent.layer.full(layerIndex2);
				refreshTable();
			}else{
				if(numberBuilder != 'tianjin712suo'){
					if(!updateNeedHandleEvent(messageId)){
						 return;
					}
				}else{updateNeedHandleEvent(messageId);}
				
				
				
				layerIndex2 = parent.layer.open({
					 type: 2,
					 title: '待办事项',
					 area: ['1000px', '350px'],
					 fixed: false, //不固定
					 maxmin: true,
					 shim: true,
					 content:url+"&messageId="+messageId+"&random="+Math.random()
				});
				parent.layer.full(layerIndex2);
				refreshTable();
			}
		}else if(parentModelName == 'KT项目管理'){
			if(numberBuilder != 'tianjin712suo'){
				if(!updateNeedHandleEvent(messageId)){
					 return;
				}
			}else{updateNeedHandleEvent(messageId);}
            parent.parent.parent.skipModule1("测试管理","${_baseUrl}/jurisdiction/menuList","e1c3fb53a4be410885154dd74d4b2631",'d42f113426d7436ba1683856cc1697a1',"","","");
        }else if(parentModelName == 'KD项目管理' ){
			if(numberBuilder != 'tianjin712suo'){
				if(!updateNeedHandleEvent(messageId)){
					 return;
				}
			}else{updateNeedHandleEvent(messageId);}
            parent.parent.parent.skipModule("文档开发","");
		}else if(parentModelName == '需求管理'){
			if(numberBuilder != 'tianjin712suo'){
				if(!updateNeedHandleEvent(messageId)){
					 return;
				}
			}else{updateNeedHandleEvent(messageId);}
			parent.parent.parent.skipModule1(parentModelName,"${_baseUrl}/jurisdiction/menuList",'69268ed838914b7c86e5a191280249d5',"4341b3b1934345b3b19dff86500b3ee7","","","");
		}else if(parentModelName == '测试阶段'){
			// sigh(messageId);
			//parent.parent.parent.skipModule1("测试管理","${_baseUrl}/jurisdiction/menuList",'',"d42f113426d7436ba1683856cc1697a1",projectId);
			//改为跳转到kdtrMenuControlle的菜单就不会出现多余的菜单，上一行注释是之前的跳转
			<%--parent.parent.parent.skipModule1("测试管理","${_baseUrl}/kdtrMenuController/menuList",'',"d42f113426d7436ba1683856cc1697a1",projectId);--%>

            // 修改bug [#15550] 我的工作台，待办（工作产品分配后，请负责人处理的代办）点击，跳转路径有误，展示为空白，详见图
            <%--parent.parent.parent.skipModule1("测试管理","${_baseUrl}/kdtrMenuController/menuList",'729f1578d1524ec6a2eaf3a4db96fe2b',"d42f113426d7436ba1683856cc1697a1",projectId,"","");--%>
            //待办跳转到 阶段过程界面
            parent.parent.closeAndSkip("测试管理",url,messageId);
		}else if(parentModelName == '变更分析' || parentModelName == '文档编写'){
			parent.parent.closeWin1(parent.layerIndex);
			if(numberBuilder != 'tianjin712suo'){
				if(!updateNeedHandleEvent(messageId)){
					 return;
				}
			}else{updateNeedHandleEvent(messageId);}
			if("KD"==tableFlag){
				parent.parent.skipModule("文档开发",url);
			}else{
				parent.parent.skipModule(parentModelName,url);
			}
		}else{
			if(numberBuilder != 'tianjin712suo'){
				if(!updateNeedHandleEvent(messageId)){
					 return;
				}

			}
			// sigh(messageId);
			layerIndex1 = parent.layer.open({
				 type: 2,
				 title: '待办事项',
				 area: ['1000px', '350px'],
				 fixed: false, //不固定
				 maxmin: true,
				 shim: true,
				 content:encodeURI(url+"&workNum=1"+"&messageId="+messageId+"&random="+Math.random()) // 处理url中存在中文参数高版本tomcat下ie不兼容,使用encodeURI进行编码
			});
			parent.layerIndex = layerIndex1;
			parent.layer.full(layerIndex1);
			refreshTable();
		}
		
	}
	
	
	
	function updateNeedHandleEvent(messageId){
		var flag = false;
		$.ajax({
			url : '${_baseUrl}/workbench/updateNeedHandleEvent?id='+messageId,
			type : 'post', //数据发送方式
			dataType : 'json', //接受数据格式
			async : false,
			success : function(json) {
				if(json.code == '0'){
					flag = true;
				}
			},
			error : function() {
				layer.msg("系统错误,请联系管理员");
			}
		});
		return flag;
	}
	
	
	/* 关闭弹出框 */
	function closeWin(){
		layer.closeAll();
		parent.layer.closeAll();
	}
	function closeWindow(){
		layer.closeAll();
	}


    function judge_enter(){
        var theEvent = window.event || arguments.callee.caller.arguments[0];
        var code = theEvent.keyCode;
        if(code==13){
            refreshTable();
        }
    }
	
</script>
</html>